#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int f = 0, ans = 0;
    char c = getchar();
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        ans = (ans << 3) + (ans << 1) + c - 48, c = getchar();
    return f ? -ans : ans;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void printws(int x, char ch = ' ')
{
    write(x);
    putchar(ch);
}
inline void println(int x)
{
    write(x);
    putchar('\n');
}
constexpr int N = 2.5e1 + 5, K0 = 1e3 + 5, mod = 1e9 + 7;
int n, K;
namespace std
{
    namespace numbers
    {
        struct int128
        {
            string s;
            int sz, f;
            int128()
            {
                s = "0", sz = 1, f = 1;
            }
        };
        int128 empty()
        {
            int128 x;
            x.s = "", x.sz = 0;
            return x;
        }
        int128 to_int128(string str)
        {
            int128 x;
            if (str[0] == '-')
                x.f = -1, str = str.substr(1);
            x.s = str, x.sz = str.size();
            return x;
        }
        int128 to_int128(int x)
        {
            int128 ans;
            if (x == 0)
                return ans;
            ans = empty();
            if (x < 0)
                ans.f = -1, x = -x;
            while (x)
                ans.s = char(x % 10 + '0') + ans.s, ans.sz++, x /= 10;
            return ans;
        }
        int128 abs(int128 x)
        {
            x.f = 1;
            return x;
        }
        int128 opp(int128 x)
        {
            x.f = -x.f;
            return x;
        }
        istream &operator>>(istream &cin_, int128 &x)
        {
            x = empty();
            char ch = getchar();
            while (ch < '0' || ch > '9')
                x.f = (ch == '-' ? -1 : 1), ch = getchar();
            while (ch >= '0' && ch <= '9')
                x.s += ch, x.sz++, ch = getchar();
            return cin_;
        }
        ostream &operator<<(ostream &cout_, int128 x)
        {
            if (x.f == -1)
                putchar('-');
            for (int i = 0; i < x.sz; i++)
                putchar(x.s[i]);
            return cout_;
        }
        bool operator<(int128 x, int128 y)
        {
            if (y.f == -1 && x.f == -1)
                return y < x;
            if (x.f == 1 && y.f == -1)
                return false;
            if (x.f == -1 && y.f == 1)
                return true;
            // cerr << "ISXY " << x.s << ' ' << y.s << " " << (x.s < y.s) << endl;
            return x.sz < y.sz || (x.sz == y.sz && x.s < y.s);
        }
        bool operator>(int128 x, int128 y)
        {
            return y < x;
        }
        bool operator<=(int128 x, int128 y)
        {
            return !(x > y);
        }
        bool operator>=(int128 x, int128 y)
        {
            // cerr << ">+ " << x.s << ' ' << y.s << " " << (x.s < y.s) << endl;
            return y <= x;
        }
        bool operator==(int128 x, int128 y)
        {
            return (x >= y) && (y <= x);
        }
        bool operator!=(int128 x, int128 y)
        {
            return !(x == y);
        }
        int128 operator+(int128 x, int128 y)
        {
            if (x.f == -1 && y.f == -1)
            {
                x.f = y.f = 1;
                return opp(x + y);
            }
            if (x.f == -1 && y.f == 1)
                return y + x;
            string a = x.s, b = y.s, res = "";
            int sa = x.sz, sb = y.sz;
            if (x.f == 1 && y.f == -1)
            {
                if (x < abs(y))
                {
                    x.f = -1, y.f = 1;
                    int128 ans = y + x;
                    ans.f = -1;
                    return ans;
                }
                for (int i = sb; i < sa; i++)
                    b = '0' + b;
                int j = 0;
                for (int i = sa - 1; i >= 0; i--)
                {
                    int t = a[i] - b[i] - j;
                    j = (t < 0), t = (t + 10) % 10;
                    res = char(t + '0') + res;
                }
                while (res.size() > 1 && res[0] == '0')
                    res = res.substr(1);
                int128 ans;
                ans.s = res, ans.sz = res.size(), ans.f = 1;
                return ans;
            }
            if (sa > sb)
                swap(a, b), swap(sa, sb);
            int128 ans;
            reverse(a.begin(), a.end());
            reverse(b.begin(), b.end());
            for (int i = sa; i < sb; i++)
                a += '0';
            int j = 0;
            for (int i = 0; i < sb; i++)
            {
                int t = a[i] + b[i] - 2 * '0' + j;
                j = t / 10, t %= 10, res += char(t + '0');
            }
            if (j)
                res += char(j + '0');
            reverse(res.begin(), res.end());
            ans.s = res, ans.sz = res.size();
            return ans;
        }
        void operator+=(int128 &x, int128 y)
        {
            x = x + y;
        }
        int128 operator-(int128 x, int128 y)
        {
            y.f = -y.f;
            return x + y;
        }
        void operator-=(int128 &x, int128 y)
        {
            x = x - y;
        }
        int128 operator*(int128 x, int128 y)
        {
            if (x.f != y.f)
            {
                x.f = y.f;
                return opp(x * y);
            }
            string a = x.s, b = y.s;
            int sa = x.sz, sb = y.sz;
            if (a == "0" || b == "0")
                return to_int128(0);
            int128 ans;
            for (int i = sb - 1; i >= 0; i--)
            {
                string m;
                int in = 0;
                for (int j = sa - 1; j >= 0; j--)
                {
                    int t = (a[j] - '0') * (b[i] - '0') + in;
                    in = t / 10, t %= 10;
                    char c = t + '0', l = in + '0';
                    m = c + m;
                    if (j == 0 && l > '0')
                        m = l + m;
                }
                for (int j = 1; j <= sb - 1 - i; j++)
                    m += '0';
                ans += to_int128(m);
            }
            return ans;
        }
        void operator*=(int128 &x, int128 y)
        {
            x = x * y;
        }
        int128 pow(int128 a, int b)
        {
            int128 res = to_int128(1);
            while (b)
                res = res * (b & 1 ? a : to_int128(1)), a *= a, b >>= 1;
            return res;
        }
        int128 fac(int n)
        {
            int128 res = to_int128(1);
            for (int i = 1; i <= n; i++)
                res *= to_int128(i);
            return res;
        }
        int128 operator/(int128 x, int128 y)
        {
            if (x.f != y.f)
            {
                x.f = y.f;
                return opp(x / y);
            }
            x.f = y.f = 1;
            if (y > x)
                return to_int128(0);
            int cur = 0;
            int128 tmp = empty(), ans = empty();
            tmp.s = x.s[0], tmp.sz++;
            while (cur < x.sz)
            {
                int res = 9;
                while (y * to_int128(res) > tmp)
                    res--;
                ans.s += char(res + '0'), ans.sz++;
                tmp -= y * to_int128(res);
                if (tmp.s == "0")
                    tmp.s = "", tmp.sz = 0;
                tmp.s += x.s[++cur], tmp.sz++;
            }
            while (ans.sz > 1 && ans.s[0] == '0')
                ans.s = ans.s.substr(1), ans.sz--;
            return ans;
        }
        void operator/=(int128 &x, int128 y)
        {
            x = x / y;
        }
        int128 operator%(int128 x, int128 y)
        {
            return x - ((x / y) * y);
        }
        void operator%=(int128 &x, int128 y)
        {
            x = x % y;
        }
        void operator++(int128 &x)
        {
            x = x + to_int128(1);
        }
        void operator--(int128 &x)
        {
            x = x - to_int128(1);
        }
    }
    namespace algorithm
    {
        using namespace std::numbers;
        inline int128 read_bin(const int128 &one, const int128 &two)
        {
            string s;
            cin >> s;
            int128 res;
            for (auto i : s)
            {
                res = (res * two);
                if (i > '0')
                    res += one;
                // cerr << "R " << res << endl;
            }
            return res;
        }
        inline void compute()
        {
            string s;
            cin >> s;
            const auto one = to_int128(1);
            const auto two = to_int128(2);
            auto a = read_bin(one, two);
            auto b = read_bin(one, two);
            // #ifdef _DEBUG
            //             cerr << "AB " << a << " " << b << endl;
            // #endif
            auto c = one;
            for (auto i : s)
            {
                c *= two;
                if (i == 'R')
                    c += one;
            }
            // cerr << "C " << c << endl;
            int128 res;
            if (c >= a && c <= b)
                res = c;
            c = one;
            for (auto i : s)
            {
                c *= two;
                if (i == 'L')
                    c += one;
            }
            // cerr << (c >= a) << " END" << endl;
            // cerr << "C " << c << "  " << a << " " << b << "  " << (c >= a) << " " << (c <= b) << endl;
            if (c >= a && c <= b)
                res += c;
            cout << res % to_int128(mod) << '\n';
        }
    }
}
int a, b;
string s;
inline int read_bin()
{
    string s;
    cin >> s;
    int res = 0;
    for (auto i : s)
        res = (res << 1) | (i - '0');
    return res;
}
signed main()
{
    freopen("lost.in", "r", stdin);
    freopen("lost.out", "w", stdout);
    cin >> n >> K;
    if (!K)
    {
        std::algorithm::compute();
        return 0;
    }
    cin >> s;
    a = read_bin();
    b = read_bin();
    vector<int> is(n - 1);
    fill(is.begin(), is.begin() + K, 1);
    sort(is.begin(), is.end());
    int res = 0;
    do
    {
        // string out;
        int is_swapped = 0;
        int c = 1;
        for (int i = 0; i < n - 1; ++i)
        {
            if (is[i])
                is_swapped ^= 1;
            c <<= 1;
            if ((!is_swapped && s[i] == 'R') ||
                (is_swapped && s[i] == 'L'))
                c |= 1;
            // char ch = s[i];
            // ch = is_swapped ? (ch == 'L' ? 'R' : 'L') : ch;
            // out.push_back(ch);
        }
        if (c >= a && c <= b)
            res += c;
        // if (c >= a && c <= b)
        //     cerr << out << " NEXT" << endl;
        is_swapped = 1;
        c = 1;
        // out = "";
        for (int i = 0; i < n - 1; ++i)
        {
            if (is[i])
                is_swapped ^= 1;
            c <<= 1;
            if ((!is_swapped && s[i] == 'R') ||
                (is_swapped && s[i] == 'L'))
                c |= 1;
            // char ch = s[i];
            // ch = is_swapped ? (ch == 'L' ? 'R' : 'L') : ch;
            // out.push_back(ch);
        }
        if (c >= a && c <= b)
            res += c;
        // if (c >= a && c <= b)
        //     cerr << out << " NEXT" << endl;
    } while (next_permutation(is.begin(), is.end()));
    cout << res << '\n';
    return 0;
}